package com.woniuxy.repayment.controller;

import com.woniuxy.commons.request.ResPage;
import com.woniuxy.commons.request.ResponseResult;
import com.woniuxy.commons.vo.ProjectVo;
import com.woniuxy.commons.vo.SearchProjectVo;
import com.woniuxy.repayment.service.RepaymentService;
import com.woniuxy.repayment.vo.RepaymentVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/repayment")
public class RepaymentController {

    @Resource
    private RepaymentService repaymentService;

    @PostMapping("/addRepayment")
    public ResponseResult<Boolean> addRepayment(@RequestBody ProjectVo projectVo){
        return new ResponseResult<>(ResponseResult.OK, repaymentService.addRepayment(projectVo));
    }

    @GetMapping("/checkRepaymentSuccess/{pno}")
    public ResponseResult<Boolean> checkRepaymentSuccess(@PathVariable("pno") String pno){
        return new ResponseResult<>(ResponseResult.OK, repaymentService.checkRepaymentSuccess(pno));
    }

    @PostMapping("/searchRepayment")
    public ResponseResult<ResPage<List<RepaymentVo>>> searchRepayment(@RequestBody SearchProjectVo searchProjectVo){
        ResPage<List<RepaymentVo>> resPage = repaymentService.searchRepayment(searchProjectVo);
        return new ResponseResult<>(ResponseResult.OK, resPage);
    }

    @PostMapping("/searchOverdues")
    public ResponseResult<ResPage<List<RepaymentVo>>> searchOverdues(@RequestBody SearchProjectVo searchProjectVo){
        ResPage<List<RepaymentVo>> resPage = repaymentService.searchOverdues(searchProjectVo);
        return new ResponseResult<>(ResponseResult.OK, resPage);
    }

}
